﻿using MusicExplorer.Converters;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Data;

namespace MusicExplorer.Common
{
    public sealed class VariableGridView : GridViewEx
    {
        public VariableGridView()
            : base()
        {
        }

        protected override void PrepareContainerForItemOverride(Windows.UI.Xaml.DependencyObject element, object item)
        {
            base.PrepareContainerForItemOverride(element, item);
            var gridItem = element as GridViewItem;
            gridItem.SetBinding(GridViewItem.IsSelectedProperty, new Binding()
                {
                    Path = new PropertyPath("IsSelected"),
                    Mode = BindingMode.TwoWay
                });
            gridItem.SetBinding(VariableSizedWrapGrid.ColumnSpanProperty,
                new Binding()
                {
                    Path = new PropertyPath("Size"),
                    Converter = new QueryGroupSizeToWidthConverter(),
                    Mode = BindingMode.TwoWay
                });
            gridItem.SetBinding(VariableSizedWrapGrid.RowSpanProperty,
                new Binding()
                {
                    Path = new PropertyPath("Size"),
                    Converter = new QueryGroupSizeToHeightConverter(),
                    Mode = BindingMode.TwoWay
                });
        }
    }
}
